package com.atguigu.gmall.product.config;


import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//表明这是一个配置类
@Configuration
public class AppMyBatisPlusConfig {

    //PaginationInnerInterceptor

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //1、先创建出总拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        //分页插件拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();

        //设置分页的一些默认属性
        paginationInnerInterceptor.setOverflow(true); //开启页码溢出处理，溢出后只是返回第一页数据
        paginationInnerInterceptor.setMaxLimit(100L); //防止数据库被恶意攻击阻塞


//        OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor = new OptimisticLockerInnerInterceptor();
//        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor);
        //2、把小拦截器 xxxxInnerInterceptor 设置给总拦截器进行管理
        interceptor.addInnerInterceptor(paginationInnerInterceptor);

        return interceptor;
    }

}
